<template>
  <el-dialog
    :visible.sync="dialogVisible"
    :show-close="showClose"
    :before-close="handleClose"
    :fullscreen="fullscreen"
    :class="customClass"
    :title="title"
    :width="width"
    :append-to-body="true"
    :close-on-click-modal="false"
    :close-on-press-escape="true">
    <slot />
    <span slot="footer" class="dialog-footer">
      <el-button @click="handleCancel">取 消</el-button>
      <slot name="footer" />
    </span>
  </el-dialog>
</template>
<script>
export default {
  props: {
    title: {
      type: String,
      required: true
    },
    showClose: {
      type: Boolean,
      default: true
    },
    width: {
      type: String,
      default: '50%'
    },
    visible: {
      type: Boolean,
      default: false
    },
    fullscreen: {
      type: Boolean,
      default: false
    },
    customClass: {
      type: String,
      default: 'common-dialog'
    }
  },
  data() {
    return {
      dialogVisible: false
    }
  },
  watch: {
    visible: function(val) {
      this.dialogVisible = val
    }
  },
  methods: {
    handleClose(done) {
      this.$confirm('确认关闭?').then(_ => {
        done()
        this.handleCancel()
      }).catch(_ => {})
    },
    handleCancel() {
      this.dialogVisible = false
      this.$emit('close')
    }
  }
}
</script>
<style scoped>

</style>
